﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ec_System.MvcService.Model;
using Ilongshi.Oversea.DataAccess;


namespace Ec_System.MvcService.DAL
{
    public class QrCodeService
    {
        /// <summary>
        /// 根据溯源码获取Product的溯源信息
        /// </summary>
        /// <param name="code">溯源码</param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public QrCodeData GetQrInfoByCode(string code, string ip)
        {
            QrCodeData model = null;
            var cmd = DataCommandManager.GetDataCommand("GetQrInfoByCode");
            cmd.SetParameterValue("@QrCode", code);
            cmd.SetParameterValue("@IP", ip);

            using (GridReader reader = cmd.ExecuteMultiple())
            {
                var qrInfo = reader.Read<QrCodeData>();
                var record = reader.Read<QrRecord>();
                if (qrInfo.Count() > 0)
                    model = qrInfo.First();
                if (record.Count() > 0)
                    model.RecordList = record.ToList();
            }

            return model;
        }
    }
}
